package org.csy.work.servlet;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.csy.work.dao.ProductDao;
import org.csy.work.dao.impl.ProductDaoImpl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author ZJL
 * @date 2024-11-25
 */
@WebServlet("/delProduct.do")
public class DelProductServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String productId = req.getParameter("productId");
        ProductDao productDao = new ProductDaoImpl();
        String message = "";
        int n = productDao.delete(productId);
        if (n > 0) {
            message = "删除成功";
        }else{
            message = "删除失败";
        }
        PrintWriter out = resp.getWriter();
        out.write(message);
        out.flush();
        out.close();
    }
}
